/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import App.Facada;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Jaso
 */
public class GUI extends JFrame implements ActionListener{

    private LoginPanel loginPanel;     

    private AccountPanel accountPanel;
    
    
    private Panel cards;
    private CardLayout cardLayout;

    private Container contentPane;
    private Panel panelContainer;
    private Label label1;
    private Button btnLogOff;
    
    private DepositPanel depositPanel;
    private WithdrawPanel withdrawPanel; 
    protected Facada facada;

    private int width;

    public GUI(Facada facada, LoginPanel loginPanel, AccountPanel accountpanel, DepositPanel depositPanel, WithdrawPanel withdrawPanel) {
        
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 
        width = 700;
        this.facada = facada;
        this.setBounds((screenSize.width-width) /2, (screenSize.height-600)/2, width, 600);
        this.loginPanel = loginPanel;
        loginPanel.setGui(this);
        this.accountPanel = accountpanel;
        accountPanel.setGui(this);
        this.withdrawPanel = withdrawPanel;
        this.depositPanel = depositPanel;
        withdrawPanel.setGui(this);
        depositPanel.setGui(this);
        
        contentPane = getContentPane();
        panelContainer = new Panel();

        initGUI();
    }
 
    
    
    public void initGUI()   {
        contentPane.setBackground(new Color (143, 188, 143));
        contentPane.setLayout(null);
                
        label1 = new Label("HKR Bank");
        label1.setBounds(width/2 - 115 , 10, 230, 50);
        label1.setBackground(new Color(153, 198,143));
        label1.setFont(new Font("Serif", Font.PLAIN, 50));
        contentPane.add(label1);
        
        
        cards = new Panel(new CardLayout());
        cards.setBounds(0, 0, width , 500);
        
        cards.add(loginPanel, "LoginPanel");
        cards.add(accountPanel, "AccountPanel");
        
        cards.add(withdrawPanel, "WithdrawPanel");
        
        cards.add(depositPanel, "DepositPanel");
        
        
        panelContainer.setLayout(null);
        panelContainer.setBounds(0, 75, width , 500);
        panelContainer.add(cards, BorderLayout.CENTER);
        contentPane.add(panelContainer);
        
        btnLogOff = new Button("Log Off");
        btnLogOff.addActionListener(this);
        btnLogOff.setBackground(new Color(189, 183, 107));
        btnLogOff.setBounds(width - 140, 10, 100, 30);
        btnLogOff.setVisible(false);

        add(btnLogOff);
        
        
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);


    }
    
    public void SwitchPanels(String s) {
        cardLayout = (CardLayout) cards.getLayout();
        
        if(s.equals("account"))   {
            accountPanel.updateCurrentBalance(facada.getCurrentBalance());
            btnLogOff.setVisible(true);
            cardLayout.show(cards, "AccountPanel");
         
        } else if (s.equals("login")) {
            btnLogOff.setVisible(false);
            loginPanel.clearTextFields();
            cardLayout.show(cards, "LoginPanel");
        } else if (s.equals("WithdrawPanel")) {
            withdrawPanel.clearTextFields();
            withdrawPanel.updateCurrentBalance(facada.getCurrentBalance());
            cardLayout.show(cards, "WithdrawPanel");
        } else if (s.equals("DepositPanel")) {
            depositPanel.clearTextFields();
            depositPanel.updateCurrentBalance(facada.getCurrentBalance());
            cardLayout.show(cards, "DepositPanel");
        }
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == btnLogOff)    { 
            SwitchPanels("login");
            
        }
    }

}

